/**
 * 基础菜单 商品管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>客户回执单</el-breadcrumb-item>
    </el-breadcrumb>

    <el-table :data="pageInFo.list" border stripe style="margin-top: 30px" @selection-change="handleSelectionChange" ref="multipleTable" tooltip-effect="dark">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" width="160" label="序号" align="center" >
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="300" align="center" sortable>
      </el-table-column>
      <el-table-column prop="number" label="单号" width="320" align="center" sortable>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="250" align="center" sortable>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope" v-if="scope.row.status=='已填'">
          <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <div style="margin-top: 20px">
      <el-button @click="delete1()" type="warning">删除选择</el-button>
      <el-button @click="toggleSelection()" type="success">取消选择</el-button>
    </div>
    <div style="padding: 10px;margin-top: 20px">
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInFo.pageNum"
        :page-sizes="[1, 2, 10, 15]"
        :page-size="pageInFo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageInFo.total">
    </el-pagination>
  </div>
  </div>
</template>
<script>
export default {
  data() {
   return {
     tableData:[],
     pageInFo:{},
     currentPage:1,
     pageNum:2,
     multipleSelection:[],
   }

  },
  created() {
        this.show()
  },
  methods:{
    handleDelete(index, row) {

      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });

        this.axios.delete("http://localhost:8080/bill/delete/"+row.number).then(res=>{
          this.show()
        })


      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    show(){
      this.axios.get("http://localhost:8080/bill/customer/"+this.currentPage+"/" + this.pageNum).then(res=>{
        this.pageInFo = res.data.data
      })
    },

    //分页方法
    handleSizeChange(val) {
      this.pageNum = val
      this.show()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.show()
    },

    //批量删除方法
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //删除批量选择
    delete1(){
      if (this.multipleSelection.length == 0){
        this.$message.error("您没有选择");
      }else {

        this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          for (const object of this.multipleSelection) {
            this.axios.delete("http://localhost:8080/bill/delete/"+object.number).then(res=>{
              this.show()
            })
          }

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

      }

    }
  }

};
</script>

<style >

</style>

 
 